/**
 * @file main.cpp
 * @brief 
 * 			Demo示例		
 * 
 * @author Zyan (zyishere2001@qq.com)
 * @version 1.0
 * @date 2022-05-07
 * 
 * @copyright Copyright (c) 2022  Zyanishere2001
 * 
 * @par 修改日志:
 * V0507
 */


#define THREAD_DEMO
//#define LOOP_DEMO


#ifdef THREAD_DEMO
//===================thread=======================

#include "PacketSniffer.h"

#include <stdio.h>
#include "ifconfig.h"
#include "EventLoop.h"

void getIpToListen(char* ip);

int main() {
    HV_MEMCHECK//检测内存分配

	char ip[16]; 
	getIpToListen(ip);
	EventLoopPtr loop(new EventLoop);

	SafeQueue<Packet_t> packetQueue;     
	PacketSniffer app(ip, packetQueue);
	app.start();

	return 0;
}


void getIpToListen(char* ip){
    std::vector<ifconfig_t> ifcs;
    ifconfig(ifcs);
	int i = 0;
    for (auto& item : ifcs) {
        printf("[index]:%d\n[ip]: %s\n[mask]: %s\n[broadcast]: %s\n[mac]: %s\n[name]:%s\n\n",
				i,
                item.ip,
                item.mask,
                item.broadcast,
                item.mac,
				item.name);
		i++;
    }
	
	std::cout << "listening to ip : [index]" ;
	std::cin >> i ;
	std::cout<< std::endl;

	i &= (ifcs.size()-1);
	//ifcs函数结束时会被回收，因此要存入变量中
	memcpy(ip,ifcs[i].ip,16);
}

#endif




